package com.zmn.oms.dubbo.impl.zmn.normal.erp;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.business.interfaces.work.erp.ErpPerformanceListBService;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.dto.zmn.erp.OrderOnTimeDRO;
import com.zmn.oms.dubbo.dto.zmn.erp.QuotationPerformanceDRO;
import com.zmn.oms.dubbo.interfaces.zmn.normal.erp.ErpPerformanceListRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.dto.work.erp.OrderOnTimeDTO;
import com.zmn.oms.model.dto.work.erp.QuotationPerformanceDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotNull;

/**
 * @author sunlife
 * @date:2021/1/18 11:40 上午
 * description:
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 5000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class ErpPerformanceListRemoteServiceImpl implements ErpPerformanceListRemoteService {

    @Autowired
    ErpPerformanceListBService erpPerformanceListBService;


    @Override
    public ResponseDTO<QuotationPerformanceDRO> getQuotationPerformance(@NotNull(message = "订单号不能为空") Long orderId, @NotNull(message = "工单号不能为空") Long workId) {
        log.info("#erp#quotationPerformance 请求入参：orderId:{} workId:{}", orderId, workId);
        try {
            QuotationPerformanceDTO quotationPerformanceDTO = erpPerformanceListBService.getQuotationPerformance(orderId, workId);
            return ResponseDTO.success(BeanMapper.map(quotationPerformanceDTO, QuotationPerformanceDRO.class));

        } catch (OmsBaseException oe) {
            log.error(String.format("获取计价器绩效错误，订单号：%s 工单号：%s", orderId, workId), oe);
            return ResponseDTO.fail(oe.getMessage());
        } catch (Exception e) {
            log.error(String.format("获取计价器绩效错误，订单号：%s 工单号：%s", orderId, workId), e);
            return ResponseDTO.fail("获取计价器绩效失败，请稍后重试");
        }
    }

    @Override
    public ResponseDTO<OrderOnTimeDRO> getOnTimePerformance(@NotNull(message = "订单号不能为空") Long orderId, @NotNull(message = "工单号不能为空") Long workId) {
        log.info("#erp#getOnTimePerformance 请求入参：orderId:{} workId:{}", orderId, workId);
        try {
            OrderOnTimeDTO onTimePerformance = erpPerformanceListBService.getOnTimePerformance(orderId, workId);
            return ResponseDTO.success(BeanMapper.map(onTimePerformance, OrderOnTimeDRO.class));

        } catch (OmsBaseException oe) {
            log.error(String.format("获取准时上门绩效错误，订单号：%s 工单号：%s", orderId, workId), oe);
            return ResponseDTO.fail(oe.getMessage());
        } catch (Exception e) {
            log.error(String.format("获取准时上门绩效错误，订单号：%s 工单号：%s", orderId, workId), e);
            return ResponseDTO.fail("获取准时上门绩效错误，请稍后重试");
        }
    }
}
